//传入参数：需要遍历的json，需要匹配的id
export function findPnodeId(data, nodeId) {
  console.log(data, nodeId)
  let parentKey = "";
  let folderId = nodeId;//当前子id
  let formFolders = data;//树数据
  let list = [];
  let parentsKeys = [];
  // 把顶级+子级都整合起来；
  let fn1 = (arr, childIds) => {
    childIds.push(arr.key);
    if (!arr.isLeaf && arr.children) {
      arr.children.forEach((item) => {
        fn1(item, childIds);
      })
    } else {
      return childIds;
    }
    return childIds;
  }
  for (let i in formFolders) {
    let obj = {
      id: formFolders[i].key,
      childIds: [],
    }
    let childIdDatas = fn1(formFolders[i], obj["childIds"]);
    obj["childIds"] = childIdDatas;
    parentsKeys.push(obj);
  };
  parentsKeys.forEach((item, index) => {
    if (item.childIds.includes(folderId)) {
      parentKey = item.id;
      console.log(parentKey)
      return;
    }
  })
  return parentKey

}
export function roomIncrease(numstare, numend, foolstare, foolend) {
  if (numstare > numend || foolstare > foolend) { return "" }
  var foolends = []
  for (var i = numstare; i <= numend; i++) {
    for (var j = foolstare; j <= foolend; j++) {
      foolends.push(i + "0" + j)
    }
  }
  return foolends
}
export function findTreeArr(arr,newarr) {
  for (let i = 0; i < arr.length; i++) {
    if (!arr[i].children) {
      newarr.push(arr[i].menuId);
    } else {
      if (arr[i].children) {
        findTreeArr(arr[i].children,newarr);
      }
    }
  }
  return newarr;
}

